package com.example.demo.strategy.CalculationStrategy;

import com.example.demo.enums.CalculationEnum;
import com.example.demo.strategy.CalculationMethodStrategy;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service(value = "DateBeforeStrategy")
public class DateBeforeStrategy implements CalculationMethodStrategy {

    @Override
    public boolean calculate(String preContent, String value) {
        ThreadLocal<LocalDate> date = new ThreadLocal<LocalDate>() {
            @Override
            protected LocalDate initialValue() {
                return LocalDate.parse(preContent);
            }
        };

        ThreadLocal<LocalDate> date2 = new ThreadLocal<LocalDate>() {
            @Override
            protected LocalDate initialValue() {
                return LocalDate.parse(value);
            }
        };

        // 这是一个静态的simpleDateFormat变量
        return date.get().isBefore(date2.get());
    }

    @Override
    public CalculationEnum getCalculationEnum() {
        return CalculationEnum.DATE_BEFORE;
    }
}
